import random
from datetime import datetime


class GenerateUtil:
    """生成测试数据工具类"""

    @staticmethod
    def get_current_date(format_str="%Y%m%d"):
        """获取当前日期字符串"""
        return datetime.now().strftime(format_str)

    @staticmethod
    def get_random_num(length=6):
        """生成指定位数的随机数字"""
        return ''.join([str(random.randint(0, 9)) for _ in range(length)])

    @classmethod
    def generate_goods_name(cls, prefix="AutoTestGoods"):
        """生成唯一商品名称"""
        return f"{prefix}_{cls.get_current_date()}_{cls.get_random_num(4)}"

    @classmethod
    def generate_sn(cls, prefix="800"):
        """生成唯一商品编号"""
        return f"{prefix}{cls.get_current_date('%y%m%d')}{cls.get_random_num(7)}"


if __name__ == '__main__':
    # 调试
    print(GenerateUtil.generate_goods_name())
    print(GenerateUtil.generate_sn())
